package com.hwl.demo18.entity;

import com.hwl.demo18.service.Command;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;

/**
 * 服务员类
 *
 * @author sentry
 * @since 2023-03-26
 */
public class Waiter {

    private final ArrayList<Command> orders = new ArrayList<>();

    public void setOrder(Command command) {
        String className = command.getClass().getSimpleName();
        if ("BakeChickenWingCommand".equals(className)) {
            System.out.println("服务员：鸡翅没有了，请点别的烧烤");
        } else {
            this.orders.add(command);
            System.out.println("增加订单：" + className + " 时间：" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        }
    }

    public void cancelOrder(Command command) {
        orders.remove(command);
        System.out.println("取消订单：" + command.getClass().getSimpleName() + " 时间：" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
    }

    public void notifyCommand() {
        for (Command order : orders) {
            order.excuteCommand();
        }
    }
}
